Laravel / Views / Master Layout Integration
Master Layout Integration
-
Steps
1.Layout of different pages
There are 4 pages in the above image. Some sections (header, left sidebar, footer ) are common to all these pages. Html code of common sections are duplicated in each pages. This approach is difficult for maintaining the layouts We can use concept of master layout to avoid the duplication of html code of common sections.
2. Concept of master layout
3. Steps to implement master page
1. Create a master.blade.php in resources/views/layouts/
2. add Html code of common sections into the master.blade.php
3. Add @Yield Directives. A yield directive is used during template processing to indicate where things go
@yield('title') @yield('content') 1. Note that the two yields 'title' and 'content'.
2. We can use many number of yields in a master blade.
3. We must define content of each yields in the child blades
4. using @section() and @endsection for defining the content of each yield4. Using the Layout
1. extend child blade from master
@extends('layouts.master') 2. Defind content of each yield() used in the master.blade.php
@section('title','Home Page') @section('content') Hello World
5. Complete code of a child blade
@extends('layouts.master') @section('title','Home Page') @section('content') Hello World